# 读取学生成绩数据
from apps.mapper.StudentMapper import StudentMapper

# 读取数据为dataframe
stu_data = StudentMapper().get_all_student_info()
# 对数据进行Kmeans聚类，分为4类
from sklearn.cluster import KMeans

# 抽取dataframe中的数据类型为float和int的记录
data = stu_data.select_dtypes(include=['float', 'int'])

# 进行Kmeans聚类
kmeans = KMeans(n_clusters=4)
kmeans.fit(data)

# 保存聚类结果
stu_data['cluster'] = kmeans.labels_
stu_data.to_csv('student_cluster.csv', index=False)
